<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title></title>
</head>
<body>
<link href="${pageContext.request.contextPath}/resources/shop/css/pagnination.css" rel="stylesheet" type="text/css"/>
<link href="${pageContext.request.contextPath}/assets/plugins/tablecloth/css/tablecloth.css" rel="stylesheet"
      type="text/css"/>
<link href="${pageContext.request.contextPath}/assets/plugins/tablecloth/css/prettify.css" rel="stylesheet"
      type="text/css"/>
<link href="${pageContext.request.contextPath}/assets/plugins/tablecloth/css/bootstrap-tables.css" rel="stylesheet"
      type="text/css"/>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/assets/plugins/tablecloth/js/jquery.metadata.js"></script>
<%--<script type="text/javascript"
        src="${pageContext.request.contextPath}/assets/plugins/tablecloth/js/jquery.tablesorter.min.js"></script>--%>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/assets/plugins/tablecloth/js/jquery.tablecloth.js"></script>
<script type="text/javascript" charset="utf-8">
    top.setMenuActionOpen("内容管理","文章管理");
    $(document).ready(function () {
        $('table#article_manage_tb input:checkbox').prop("checked", false);
        $("table#article_manage_tb").tablecloth({
            theme: "default",
            striped: true,
            sortable: false,
            bordered: true,
            clean: true,
            cleanElements: "th td",
            condensed: true
        });
        $('table#article_manage_tb th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                    .each(function () {

                        this.checked = that.checked;
                        $(this).closest('tr').toggleClass('selected');
                    });
        });
        $('table#article_manage_tb input:checkbox').on('click', function () {
            var that = this;
            var checked = getChecked();
            if (checked.length > 0) {
                $("#article_manage_delete_btn").removeClass("disabled").off("click").on("click", deleteArticles);
            } else {
                $("#article_manage_delete_btn").addClass("disabled").off("click");

            }
        });
    });

    function getChecked() {
        var checkbox_checked = $('table#article_manage_tb td input:checkbox:checked');
        var array = new Array();
        $(checkbox_checked).each(function (i, v) {
            var aid = $(v).attr("aid");//文章id
            if (aid && $.trim(aid).length > 0) {
                array.push(aid);
            }
        });
        return array;
    }

    function deleteArticles() {
        var checkedArray = getChecked();
        if (checkedArray && checkedArray.length > 0) {
            Common.confirm("您确定要删除选择的文章吗?",function(r){
               if(r){
                   $("#article_delete_form").empty();
                   $(checkedArray).each(function(i,v){
                       $("#article_delete_form").append("<input type='text' readonly name='id' value='"+v+"' />");
                   });
                   $("#article_delete_form").submit();
               }
            });
        }else{
            Common.notice("请选择您要删除的文章");
            return;
        }
    }
</script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/shop/js/pagination.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/jquery.dataTables.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/assets/js/jquery.dataTables.bootstrap.js"></script>
<form id="article_delete_form" method="post" action="${pageContext.request.contextPath}/admin/article/delete.html" style="display: none;"></form>
<button id="article_manage_delete_btn" class="btn disabled btn-sm btn-danger"><i class="icon-trash icon-only"></i>删除
</button>
<button onclick="window.location.href='${pageContext.request.contextPath}/admin/article/add.html'" class="btn btn-sm btn-primary"><i class="icon-share-alt icon-only"></i>添加</button>
<table id="article_manage_tb" width="100%">
    <thead>
    <tr>
        <th align="center" class="{sorter: false}"><input type="checkbox"/></th>
        <th>标题</th>
        <th>文章分类</th>
        <th  width="80">是否发布</th>
        <th width="150">创建日期</th>
        <th width="70" class="{sorter: false}">操作</th>
    </tr>
    </thead>

    <tbody>
    <c:forEach items="${requestScope.data.data}" var="item">
        <tr>
            <td align="center"><input aid="${item.id}" type="checkbox"/></td>
            <td>${item.title}</td>
            <td>${item.articleCategory.name}</td>
            <td>
                <c:choose>
                    <c:when test="${item.isPublication}">
                        <span class="label label-success">
												已发布
											</span>
                    </c:when>
                    <c:otherwise>
<span class="label label-warning">
												未发布
											</span>
                    </c:otherwise>
                </c:choose>

            </td>
            <td >
                <fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss"
                                value="${item.createDate}"/>
            </td>
            <td >
                <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                    <a target="_blank" class="blue"
                       href="${pageContext.request.contextPath}/article/content.html?id=${item.id}">
                        <i class="icon-zoom-in bigger-130"></i>
                    </a>

                    <a class="green"href="${pageContext.request.contextPath}/admin/article/edit.html?id=${item.id}">
                        <i class="icon-pencil bigger-130"></i>
                    </a>
                </div>
            </td>
        </tr>
    </c:forEach>


    </tbody>
</table>
<div id="kkpager" style="text-align: right;width: 99%;"></div>
<table id="dg"></table>
<script type="text/javascript">
    kkpager.generPageHtml({
        pno: '${requestScope.data.pageNow}',
        mode: 'link', //可选，默认就是link
        //总页码
        total: '${requestScope.data.pageNum}',
        //总数据条数
        totalRecords: '${requestScope.data.dataNum}',
        //链接前部
        hrefFormer: '${pageContext.request.contextPath}/admin/article/manage.html?pageSize=${requestScope.data.pageSize}&pageNow=',
        //链接算法
        getLink: function (n) {
            return this.hrefFormer + n;
        },
        isShowTotalPage: true,
        isShowTotalRecords: false,
        isGoPage: false
    });
    using("datagrid",function(){
        $('#rolemanage_datagrid').datagrid({
            url:'${pageContext.request.contextPath}/admin/article/getManageArticlesAjax.html',
            fitColumns:true,
            striped:true,
            method:'post',
            idField:"id",
            pagination:true,
            rownumbers:true,
            sortName:'id',
            sortOrder:'desc',
            columns:[[
                {field:'title',title:'Code',width:100},
                {field:'createDate',title:'Name',width:100},
                {field:'isTop',title:'Price',width:100,align:'right'}
            ]],
            loadFilter:function(data){
                console.info(data.success.rows[3].$ref)
                return data.success;
            }
        });
    });
</script>
</body>
</html>
